<?php
if(!defined('IN_FANWE'))
	exit('Access Denied');

class Cron
{
	public function run()
	{
		$crons = array();
		$res = DB::query("SELECT * FROM ".DB::table('cron')." WHERE run_time <= '".TIME_UTC."' ORDER BY run_time DESC");
		while($data = DB::fetch($res))
		{
			$crons[$data['type']][] = $data;
		}

		if(count($crons) > 0)
		{
			$query = DB::query("DELETE FROM ".DB::table('cron')." WHERE run_time <= '".TIME_UTC."'");
			if($query !== FALSE && DB::affectedRows() > 0)
			{
				@set_time_limit(1800);
				foreach($crons as $ctype => $cron_list)
				{
					S($ctype)->runCron($cron_list);
				}
			}
		}
	}
}
?>